package jk.fox.transport.netty.client;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import jk.fox.common.payload.response.RpcResponse;
import jk.fox.transport.ClientTransporter;
import org.apache.log4j.Logger;

/**
 * @author cuichao
 * @Description: RpcClientChannelHandler
 * @Date: create in 2020/3/28 13:15
 */
@ChannelHandler.Sharable
public class RpcClientChannelHandler extends SimpleChannelInboundHandler<RpcResponse> {

    private static Logger logger = Logger.getLogger(RpcClientChannelHandler.class);


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx,cause);
        logger.warn(cause);
    }


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RpcResponse response) throws Exception {
        ClientTransporter.selector.get(response.getRequestId()).put(response);
    }
}
